package com.nf.health.app.myfamily.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;

import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.utils.ViewUtil;

/** 
 * @ClassName: OldSettongNameActivity 
 * @Description: 老人机设置名称
 * @author Ian 
 * @date 2015-11-18 下午3:19:02 
 *  
 */
public class OldSettongNameActivity extends BaseActivity {

	private ImageView titlebar_right_view;

	private EditText old_name;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitleBar(R.layout.titlebar_base);
		setContent(R.layout.activity_old_settong_name);

		initView();
	}

	private void initView() {
		// TODO Auto-generated method stub
		titlebar_right_view = (ImageView) findViewById(R.id.titlebar_right_view);
		old_name = (EditText) findViewById(R.id.ed_oldName);
		ViewUtil.setText(this, R.id.titlebar_title_tv, "修改名称");
		titlebar_right_view.setImageResource(R.drawable.ic_title_send);

		titlebar_right_view.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String value = old_name.getText().toString();	
				if(TextUtils.isEmpty(value)){
					showToast("修改名称不可为空");
				}else if(value.length()>10){
					showToast("名称不超过10个字");
				}else{
					
//					if(getIntent().getStringExtra("type").equals("family")){
						provider.requestUpdateName(getIntent().getStringExtra("touserid"),old_name.getText().toString(),"updatename");
//					}else{
//						provider.requestUpdateName(getIntent().getStringExtra("touserid"),old_name.getText().toString(),"updatename");
//					}

				}
			}
		});
	}
	@Override
	public void handleActionSuccess(String actionName, Object object) {
		super.handleActionSuccess(actionName, object);
		if (actionName.equals("updatename")) {
			String aa = object+"";
			if(aa.contains("成功")){
				showToast("名称修改成功");
				
				
//				Bundle bundle = new Bundle();
//				bundle.putSerializable("title",old_name.getText().toString());
//				ActivityUtils.showActivity(OldSettongNameActivity.this, FamilyMemberActivity.class, bundle);
				finish();

			}
		}
	}
}
